/*
 * launcher_robot12.cpp
 *
 */

#include "../middleware/CommunicationDespacho.h"
#include "../middleware/CommunicationRobot16.h"
#include "../middleware/CommunicationAdpt.h"
#include "../channel_common/AgentIdManager.h"
#include "../channel_common/ChannelInterface.h"
#include "../IPC/ProcessAux.h"
#include "../common/Argv.h"
#include "../capa_servicios_distribuidos/QueueLauncher.h"
#include "../middleware/CommunicationVendedor.h"
#include "../control/clienteCommon.h"
#include "../application/AdminKeys.h"
#include "../middleware/CommunicationAGV.h"
#include "../middleware/CommunicationCanastos.h"
#include "../middleware/CommunicationRobot11.h"
#include "../middleware/CommunicationRobot12.h"

using namespace middleware;

int main(int argc, char**argv)
{
	CLogger::create("Terminator del Robot 12");
	std::string hostName = "robot12_pc";

	Argv args;
	args.pushArg(hostName);

	channel::ChannelInterface::disconnectChannel(hostName);
	channel::ChannelInterface::destroy(hostName);

	AdminKeys adminZonaIzq(ZONA_IZQ);
	AdminKeys adminZonaMedio(ZONA_MED);
	AdminKeys adminZonaDer(ZONA_DER);

	CLogger::log("Destruyendo AGV");
	try {
		CommunicationAGV::destroy(adminZonaIzq.getCanastosKey(), hostName);
		CommunicationAGV::destroy(adminZonaDer.getCanastosKey(), hostName);
		CommunicationAGV::destroy(adminZonaMedio.getCanastosKey(), hostName);
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Destruyendo canastos");
	try {
		CommunicationCanastos::destroy(adminZonaIzq.getCanastosKey());
		CommunicationCanastos::destroy(adminZonaDer.getCanastosKey());
		CommunicationCanastos::destroy(adminZonaMedio.getCanastosKey());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Destruyendo robot 11");
	try {
		CommunicationRobot11::destroy(adminZonaIzq.getRobot11Key());
		CommunicationRobot11::destroy(adminZonaDer.getRobot11Key());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Destruyendo robot 12");
	try {
		CommunicationRobot12::destroy(adminZonaMedio.getLeftRobot12Key());
		CommunicationRobot12::destroy(adminZonaMedio.getRightRobot12Key());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}
}
